package com.song.shop.controller;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Song Yinghui
 * @date 2018/11/3
 * @Version 1.0
 */

@RestController(value = "rocketmq")
public class RocketMqController {

    @Autowired
    private DefaultMQProducer defaultMQProducer ;

    @RequestMapping(value = "rocketTest")
    public String test(){
        System.out.println("----------------------------------------------------------");
        Message message = new Message("songtopic" , "Tag1" , "这是一个测试，来之请求的消息".getBytes());
        message.setDelayTimeLevel(3);
        try {
            defaultMQProducer.send(message);
        } catch (Exception e) {
            e.printStackTrace();
            return "error" ;
        }
        return "success" ;
    }

    @RequestMapping(value = "rocketTest2")
    public String test2(){
        System.out.println("----------------------------------------------------------");
        Message message = new Message("broker-a" , "Tag1" , "这是一个测试，来之请求的消息".getBytes());
        message.setDelayTimeLevel(3);
        try {
            defaultMQProducer.send(message);
        } catch (Exception e) {
            e.printStackTrace();
            return "error" ;
        }
        return "success" ;
    }


}
